import Vue from 'vue'
import Router from 'vue-router'
import Menu from '../views/Menus/menu.vue'
import Login from '../views/Login/login.vue'

Vue.use(Router)

const router = new Router({

  mode: 'hash',
  base: process.env.BASE_URL,
  routes: [{
      path: "*",
      redirect: '/login'
    },
    {
      path: "/",
      component: Login
    },
    {
      path: "/login",
      component: Login
    },
    {
      path: "/",
      component: Menu,
      name: "menu",
      children: [
        // // 二级路由
        {
          path: "home",
          component: () => import(/* webpackChunkName: "home" */ '../views/Home.vue'),
          meta: { title: '首页' }
        },
        // {
        //   path: "about",
        //   component: () => import(/* webpackChunkName: "home" */ '../views/About.vue')
        // },


      ]
    },


  ]
})
// 判断进入其他页面有没有先登录  
// router.beforeEach((to, from, next) => {
//   const isLogin = localStorage.loginToken ? true : false;
//   if (to.path == "/login") {
//     if(isLogin) {next('/home')} else {next();}    
//   } else {
//     isLogin ? next() : next('/login')
//   }
// })
// router.beforeEach((to,from,next)=>{
//   if(to.path == '/login' || to.path == '/Home'){
//     next();
//   }else{
//     alert('您还没有登录，请先登录');
//     next('/login');
//   }
// })
export default router